ASDV-Cpp/Assignments/MP2_CalebFontenot_clion/main.cpp

127 lines
3.8 KiB
C++

2024-03-06 08:02:24 +07:00
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/cppFiles/main.cc to edit this template
*/
/*
* File: main.cpp
* Author: caleb
*
* Created on March 4, 2024, 7:18 PM
*/
#include <iostream>
#include <ncurses.h>
2024-03-07 10:16:43 +07:00
#include <vector>
2024-03-06 08:02:24 +07:00
using namespace std;
#include "rockPaperScissors.h"
#include "main.h"
2024-03-07 10:16:43 +07:00
#include "2DArrayOperations.h"
2024-03-06 08:02:24 +07:00
int main(){
2024-03-07 10:16:43 +07:00
std::vector<std::vector<int>> vector = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
2024-03-06 08:02:24 +07:00
int ch;
static int selection = 0;
static int * selectionPointer = &selection;
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
//clear();
do {
switch(ch) {
case KEY_UP:
--selection;
break;
case KEY_DOWN:
++selection;
break;
case '\n':
getch();
endwin();
switch (selection) {
case 0:
gameLoop();
break;
case 1:
2024-03-07 10:16:43 +07:00
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
printf("2D Vector:\n%s\n", printVector(vector).c_str());
printf("getTotal: %i\n", getTotal(vector));
printf("getAverage: %i\n", getAverage(vector));
printf("getRowTotal 0: %i\n", getRowTotal(vector, 0));
printf("getColumnTotal 0: %i\n", getColumnTotal(vector, 0));
printf("getHighestInRow 0: %i\n", getHighestInRow(vector, 0));
printf("getHighestInColumn 0: %i\n", getHighestInColumn(vector, 0));
printf("getLowestInRow 3: %i\n", getLowestInRow(vector, 3));
printf("getLowestInColumn 3: %i\n", getLowestInColumn(vector, 3));
cout << "Press Enter to Continue";
getchar();
2024-03-06 08:02:24 +07:00
break;
case 2:
2024-03-07 10:16:43 +07:00
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
cout << "Press Enter to Continue";
getchar();
2024-03-06 08:02:24 +07:00
break;
}
break;
default:
break;
}
// Ensure selection stays within bounds
selection = (selection < 0) ? 0 : selection;
selection = (selection > 2) ? 2 : selection;
//std::system("clear");
move(0, 0);
printw("%s", printMenu(selectionPointer).c_str());
refresh();
} while ((ch = getch()) != '#');
getch();
endwin();
}
std::string printMenu(int* selection) {
const int ARRAY_SIZE = 3;
std::string outputString = "";
std::string cursor[ARRAY_SIZE] = {"> ", " ", " "};
std::string menu[ARRAY_SIZE] = {"Rock Paper Scissors", "2D Arrays", "Binary Search"};
//printf("%i", *selection);
/*
if (*selection >= ARRAY_SIZE - 1) {
*selection = 0;
}
if (*selection < 0) {
*selection = ARRAY_SIZE - 1;
}
*/
std::string temp;
for (int j = 0; j < *selection; ++j) {
temp = cursor[j];
cursor[j] = cursor[j + 1];
cursor[j + 1] = temp;
}
//cursor[0] = temp;
outputString.append("Use the arrow keys to navigate the menu. Press # to exit.\n");
for (int i = 0; i < ARRAY_SIZE; ++i) {
outputString.append(cursor[i]);
outputString.append(menu[i]);
outputString.append("\n");
}
return outputString;
}