Monday, February 27, 2023

C++ Returns as Immutable

 Welcome to my Blog!

Quote of the Week

I'd Rather Piss than Pink
-Matt

Hello, lovey people who come to read my blog! This is what I've been working on in the past week. I was mostly working on the gameshow. However, I did get a chance to slip in some C++ code. Huzzah we're finally back to learning C++! Let's get into it.

 Game Show:

So, to start I've designed a new logo for the show and generally cleaned up the UI a bit more. I'm taking a class on graphic design, I try to use principals of this to make my programs look, and I quote "less disgusting". Here's what the design looks like right now.

If you notice the top, it looks like I've got a professional logo done for it. I don't know how professional you could call it since I made it with an online text generator, but I think the colors mesh well.

 

C++ Code:

Now onto the more technical stuff! This week I started a new section of the "C++ all in one book for dummies." This section claims to focus on Functional Programming. Currently, I'm learning about the principles of what makes functional programming different. This includes understanding lambdas, working with "struct", constant data, the application state, and more. This is the first time I'm seeing new built-in header libraries being used. These are <fstream> and <algorithm>. I'm excited to learn more about this and use it in my future coding ventures.

Here's a snip it of code that I was working on.

 #include <iostream>

#include <fstream>
#include <algorithm>

 

using namespace std;

 

//Avoiding Use of State Directly
//Application state is a condition that occurs when the application performs tasks that modify global data 
//It doesn't have one when using functional programming, which is good and bad. It's bad as the application has no memeory

 

int lineCount1(string filename) {
int lineCount = 0;
char c = ' ';
ifstream thisFile(filename);
while (thisFile.get(c)) {
if (c == '\n') lineCount++;
}
thisFile.close();
return lineCount;
}
int lineCount2(string filename) {
ifstream thisFile(filename);
return std::count
(istreambuf_iterator<char>(thisFile), istreambuf_iterator<char>(), '\n');
}
int main() {
const string filename = "ToeBeans.txt";
cout << lineCount1(filename) << endl;
cout << lineCount2(filename) << endl;
return 0;
}


//Making Imutable or Constant Data 
/*
struct Immutable {
int val{ 7 };
};
int main() {
const int *test1 = new int(5);
*test1 = 10;
const int test2{ 6 };
test2 = 11;
const Immutable test3;
test3.val = 12;
//The code should give an error as they should be immutable with means they cannot be re-assigned.
cout << *test1 << test2 << test3.val << endl;
return 0;
};
*/

That will conclude this week's post. I hope you enjoyed reading it! The main goal of this site is to show myself how far I've come about a year from now, so I really appreciate you reading this. It's like you're on a coding journey with me! But being a nerd aside, I'll see you guys next week!

-Peace💣 

Monday, February 20, 2023

Nerd's Hour - A Japanese Gameshow Americanized.

 Welcome to my Blog!


This is Nerd's Hour a Game Show that will Appear at the Comic-Con!

So first ahhhhhh IT'S CRAZY THAT I'M RUNNING A GAME SHOW, RIGHT? Oh, before I forget and start rambling with code here's your quote of the week.

Quote of the Week:
A dollar makes me holler!

-A Sorority Girl at the Cookie Sale.

Hello everyone; welcome back to my blog. I've decided to continue my non-voluntary strike of learning C++ and do actual projects in Python with Tkinter. The picture above is my game show's layout board or main menu. I got the idea for it while attending a Comic-Con in Canada. The land of the maple syrup that I love so much (I'm American).


The game works as follows. There are ten panels on the board, and a contestant comes up to the board and chooses one. After choosing one, they are prompted with any of the following categories.


Trivia - Audio Question - Guess that Silhouette - Videogame Challenge - Brutal Question


If they get the question right, they get a point, and the block disappears. They then move on to choose another question on the board. Until they get a question wrong, they will "lose their streak," as I like to say. If they had the highest streak, they stay up top on the "Winner's Couch". This is until someone beats their streak. If their streak gets beaten, they get kicked off the couch but sent away with some prizes. The whole goal is to stay on the sofa till the end of the show, so you can get the Grand Prize, which I will keep a secret for now 🤐.


Some people may say people are going to metagame and wait till the last minute to steal it away...

You'd be right if I were planning on handpicking people. This game's contestants will be chosen out of entire chance. Every audience member will be given a card with a number on it. Then I'll pull a random number within that range from a python script. It will look somewhat simple like this:


import random


maxValAudience = int(input())


print(random.randint(0,maxValAudience+1))


*Kids and Adults at home, this simple Python code can be used! (on the house 😉)



This will give everyone an equal chance to participate in the competition. Now as I said in the beginning, I did promise I'd write about the code. Here's your fix code heads. This is made up of 4 Python using the Pandas, Tkinter, and OpenCV libraries. I'll only show you a snippet of them for right now so as not to spoil all the questions for anyone participating in the show. If you'd like to purchase the rest, please refer to my email "patrickmadon130@gmail.com".


Snippet from ques.py
#This is where the information for the question contents and the button commands lie.
from tkinter import *
import pandas as pds
import Counter
import musicShadows
import os


def quesSel(Cbutton,number):


successVal = "Correct!"
failVal = "Wrong."
button1x = 1300
button1y = 550
button2y = 700

ques = Tk()
ques.title("Question")
ques.attributes('-fullscreen', True)
ques.config(background='Black')
ques.resizable(False, False)

if number == 0: #Trivia
file = "TriviaQuestions.xlsx"
fr = open("Counters\\trivia.txt")
value = int(fr.read())
fr.close()
imageref = musicShadows
# Read Excel and select a single cell (and make it a header for a column)
Ques = pds.read_excel(file, 'Sheet1', index_col=None, usecols="A", header= value,nrows=0)
choices = pds.read_excel(file, 'Sheet1', index_col=None, usecols="B", header= value, nrows=0)
Qvalue = Ques.columns.values[0] # this must always be at 0
Cvalue = choices.columns.values[0]
# Title
C = Canvas(ques, bg="#d0c0cc", height=500, width=1500)
C.place(x=10, y=10)
titleText = Label(ques, text="Trivia Question!", fg = "Green",font=('Californian FB', 80), bg="White")
titleText.place(x=10, y=40)
questionText = Label(ques, text=Qvalue, font=('Helvetica', 50), bg="#d0c0cc")
questionText.place(x=10, y=180)

# Text
qBox = Canvas(ques, bg="grey", height=300, width=1250)
qBox.place(x=20, y=550)
questionText = Label(ques, text=Cvalue, font=('Helvetica', 30), bg="grey")
questionText.place(x=30, y=580)

#Real Answer
# Reveal Button
reveal = Button(ques, text="Reveal", font=('Helvetica', 15), height=5, width=20, command=lambda
: imageref.revealAns(value,ques,file))
reveal.place(x=1000, y=550)


Here's a Picture of the one of the question prompts.


Hopefully, this week, I'll be working on structures of C++ again, but I hope you enjoyed a little showcase of my new project! Any feedback would be greatly appreciated, as long as it's constructive.

Until Next Time, Peace! 💣

Monday, February 13, 2023

Constructing A Gameshow + Finalizing the Card the Creator

 Welcome to the Blog!


Quote of the Week:
If I think my brain is Michael Jordan, that means I'm Michael Jordan
-An Online Classmate 

This previous week was pretty hectic, so I didn't get to do any lessons in C++. However I did finalize the designs for the Personal Pokémon Card Creator. I've also been working on a gameshow project called "Thrown Remotes". The screenshot above is a very early rough draft of how a question will look. 

The finalized version of the PPCC outputs a card front and back onto a webpage specific to it. This includes the weaknesses and resistances of the card and a backing that looks similar to the actual Pokémon card, with a degenerate easter egg.

This is a drastically shorter post than usually, but I hope you guys can wait until next week, when we'll get back into the swing of things. 

-Peace💣


Monday, February 6, 2023

Code Theory and Mediating a Code Car.

 Welcome to the Blog!



This previous week we mainly focused on code structures, such as "Singleton" and "Mediators." This was harder to grasp than pointers, believe it or not. I get them in concept but using them in practice might prove to be a harder beast to tame. Let's get into it.

Quote of the Week:
Yu-gi-oh is like playing Pokémon without the fun.
-Game Club Member.

So we first started with a singleton. This structure mainly focused on making sure there was only one instance of the code running at once or determining how many instances of the code are currently running. I made my own version of their "planets" code. This was to make it easier to understand and give me more experience with the structure. I'll put both in.

My Code:
#include <iostream>

using namespace std;

class instanceObj {
private:
string catName = "Default";
int instanceCounter = 0;
public:
instanceObj(string name);
int increase(int val);
int showCount();
};

instanceObj::instanceObj(string name)
{
catName = name;
cout << "Let's Begin" << endl;
}

int instanceObj::increase(int val)
{
instanceCounter += val;
return 0;
}

int instanceObj::showCount()
{
cout << catName << " Jumped " << instanceCounter << " Times!" << endl;
return instanceCounter;
}


int main() {
instanceObj catJump("Gerald");
catJump.increase(4);
catJump.showCount();

};

Their Code:

class Planet {
private:
static Planet* inst;
Planet(string name) {
cout << "Welcome to " << name << endl;
} // Pre-Constuctor
~Planet() {} //Deconstructor
public :
static Planet* GetInstance(string name);
};

Planet *Planet:: inst = 0;

Planet* Planet::GetInstance(string name) 
{
if (inst == 0) {
inst = new Planet(name);
}
return inst;
}


int main() {
Planet *MyPlanet = Planet::GetInstance("Earth");
cout << "MyPlanet address: " << MyPlanet << endl;

Planet* MyPlanet2 = Planet::GetInstance("Uranus");
cout << "MyPlanet address: " << MyPlanet2 << endl;
return 0;
}


Then I proceeded to go through observers and mediators, theses were initially pretty difficult to grasp, but in the end, I found that they're pretty self-explanatory. The observers look into your code and decide if anything is going unexpectedly or if it takes information from a class to put inside another. The mediators act as a backbone, where you make a flowchart esk diagram and make the program and classes from that. 
The example they gave was pretty lengthy, in which you were to design a hypothetical car. Due to the vast size of the example, I'll only include the header file. This should give you an idea of how big the system is.

Code:

#ifndef MEDIATOR_H_INCLUDED
#define MEDIATOR_H_INCLUDED

class CarPart;
class Engine;
class Electric;
class Radio;
class SteeringWheel;
class Wheels;
class Brakes;
class Headlights;
class AirConditioner;
class Road;

class Mediator {
public:
Engine* myEngine;
Electric* myElectric;
Radio* myRadio;
SteeringWheel* mySteeringWheel;
Wheels* myWheels;
Brakes* myBrakes;
Headlights* myHeadlights;
AirConditioner* myAirConditioner;
Road* myRoad;
Mediator();
void partChanged(CarPart* part);
};

class CarControls : public Mediator {
public:
void startCar();
void stopCar();
void pushGasPedal(int amount);
void releaseGasPedal(int amount);
void pressBrake(int amount);
void turn(int amount);
void turnOnRadio();
void turnOffRadio();
void adjustRadioVolume(int amount);
void turnOnHeadlights();
void turnOffHeadlights();
void climbHill(int angle);
void descendHill(int angle);
void turnOnAC();
void turnOffAC();
void adjustAC(int amount);
int getSpeed();
CarControls() : Mediator() {}
};

#endif // MEDIATOR_H_INCLUDED

Other than that, nothing code focused really happened. Other than new ideas for robots and tweaking some older projects here and there. Maybe next week, I'll post about one of those.

Until Next Time, Peace!💣

DOCTOR! The Calculator is Terminal!! The C++ variety ;)

    Hello, and Welcome to my Blog!  If you're a returning visitor, ...Hello Again! Quote of the Week: ..but fear itself isn't worthy...